<!--历史记录-->
<template lang="pug">
  kalix-master
    div.PersonalCenter
      div.bgc
        img(src="/static/PersonalCenter/u3696.jpg")
      div.personal
        div.personal-left
          div.HeadPortrait
            <!--img(src="static/PersonalCenter/u3741.png")-->
            img(:src="userIcon")
          div.xinxi
            router-link(v-bind:to="{name:'PersonalCenter'}")
              p 个人信息
            router-link(v-bind:to="{name:'InQuire'}")
              p 学分查询
            router-link(v-bind:to="{name:'Collection'}")
              p 我的收藏
            router-link(v-bind:to="{name:'History'}")
              p.information 历史记录
            router-link(v-bind:to="{name:'CourseManagement'}")
              p 课程管理
            div(v-if="isTeacher")
              router-link(v-bind:to="{name:'LiveManagement'}")
                p 直播管理
        div.personal-right
          div.title
            span {{username}}
          div.center
            div.record
              span.record-span( v-for="(item,index) in items"  @click="isName(item,index)"  :class="index === isIndex?'Greens':''") {{ item.title }}
            div.kecheng-son
              ul
                li.kecheng-li(v-if="isIndex===0" v-for="(item, index) in gongkai" @click="router(item)")
                  div.kecheng-img
                    img(:src="item.photo")
                    p {{item.name}}
                li.kecheng-li(v-if="isIndex===1" v-for="(item, index) in jingpin" @click="router(item)")
                  div.kecheng-img
                    img(:src="item.photo")
                    p {{item.name}}
                li.kecheng-li(v-if="isIndex===2" v-for="(item, index) in weike" @click="router(item)")
                  div.kecheng-img
                    img(:src="item.photo")
                    p {{item.name}}
</template>

<script type="text/ecmascript-6">
  export default {
    data() {
      return {
        isTeacher: false,
        uid: '',
        username: '',
        userIcon: '',
        isIndex: 0,
        items: [
          {title: '公开课'},
          {title: '精品课'},
          {title: '微课'}
        ],
        gongkai: [],
        jingpin: [],
        weike: []
      }
    },
    mounted() {
      this.uid = this.$KalixCatch.get('id')
      this.username = this.$KalixCatch.get('user_name')
      this.getHeadImg(this.uid)
      this.getHistoryByUid()
      this.getRid()
    },
    methods: {
      getRid() {
        this.axios.get('/camel/rest/roles', {
          params: {
            jsonStr: {'name': '教师'}
          }
        }).then(res => {
          if (res.data.totalCount > 0) {
            this.getRole(res.data.data[0].id)
          }
        })
      },
      getRole(rid) {
        this.axios.get('/camel/rest/roles/' + rid + '/users/ids', {
          params: {
            id: rid
          }
        }).then(res => {
          for (let i = 0; i < res.data.length; i++) {
            if (res.data[i] === parseInt(this.uid)) {
              this.isTeacher = true
            }
          }
        })
      },
      getHeadImg(id) {
        this.axios.request({
          method: 'GET',
          url: '/camel/rest/users/' + `${id}`
        }).then(res => {
          this.userIcon = res.data.data[0].icon
        })
      },
      router(item) {
        this.$router.push({name: 'VideoPage', params: {id: item.id}})
      },
      getHistoryByUid() {
        this.axios.request({
          method: 'GET',
          url: '/camel/rest/user/historys/getHistoryByUid',
          params: {
            uid: this.uid
          }
        }).then(res => {
          // eslint-disable-next-line
          res = eval("(" + res.data + ")")
          this.gongkai = res.gCourse
          this.jingpin = res.jCourse
          this.weike = res.wCourse
        })
      },
      isName(item, index) {
        this.isIndex = index
      }
    }
  }
</script>

<style scoped lang="stylus" rel="stylesheet/stylus">
  .bgc
    width 100%
    height 327px
    position absolute
    top 100px
    z-index -1

  .bgc img
    width 100%
    height 100%

  .personal
    width 1200px
    height 718px
    /*background-color: green*/
    background-color: #fff
    margin 0 auto
    margin-top 186px
    position relative
    border-radius 5px
    box-shadow 4px 4px 6px #ccc

  .personal-left
    width 18%
    height 100%
    float left
    position: relative

  .personal-right
    width 80%
    height 100%
    float right

  /*头像*/
  .HeadPortrait
    width 150px
    height 150px
    position: absolute
    right 0
    top -75px

  .HeadPortrait img
    width 100%
    height 100%

  .xinxi
    position absolute
    top 110px
    right 0
    width 150px
    /*height 300px*/
    border 1px solid #ccc
    border-radius 5px
    overflow hidden

  .xinxi p
    display block
    width 150px
    height 50px
    text-align center
    line-height 50px
    color #999
    box-sizing border-box
    border-top 1px solid #ccc

  .xinxi .information
    background-color: #008F95
    color #fff
    font-weight 700
    border-top none

  /*右侧*/
  .title
    margin-top 36px

  .title span
    font-size 20px
    margin-right 14px
    color #000
    font-weight 700

  .center
    width 905px
    height 520px
    border 1px solid #ccc
    border-radius 5px
    margin-top 54px
    padding-left 36px
    padding-top 33px

  .record
    margin-bottom 24px

  .record-span
    margin-right 36px
    color #666
    cursor pointer
    font-size 18px

  .kecheng-img
    width 100px
    height 140px

  .kecheng-img img
    width 110px
    height 80px

  .kecheng-img p
    display block
    width 100px
    height 40px
    line-height 40px
    text-align center

  .kecheng-son
    text-align center

  .kecheng-son ul
    display flex
    flex-wrap wrap
    /*justify-content space-around*/
    align-items flex-start

  .kecheng-li
    margin-right 26px

  .Greens
    color #008F95
    font-weight 700
</style>
